/*
 * Created on Feb 8, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package littlecyberwar.ui;

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import littlecyberwar.tool.MouseHandler;
import littlecyberwar.ui.*;
import littlecyberwar.util.*;


/**
 * @author Milton  Soong
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class ModeAction extends LCWAction {
	
	public static final String LCW_MOUSEHANDLER="LCW_MOUSEHANDLER";
	
  PlayingBoardPanel pbp;
  public ModeAction(String text, 
  					ImageIcon icon,
					String desc, 
					KeyStroke k, 
					JFrame fr, 
					PlayingBoardPanel pbpIn, 
					String mouseHandlerClassName) {
	  super(text, icon, desc, k, fr);
	  pbp = pbpIn;
	  // The class for the action is loaded here
	  MouseHandler	handler=null;	
	  if ( mouseHandlerClassName != null ) {
		 ClassLoader loader = this.getClass().getClassLoader();
		 try {
		   Class cl = loader.loadClass("littlecyberwar.tool." + mouseHandlerClassName);
		   handler = (MouseHandler)cl.newInstance();

		 } catch ( Exception ex ) {
		   ex.printStackTrace();
		 }
		 if ( handler != null ) {
		  handler.setBoardPanel(pbp);
		  putValue(LCW_MOUSEHANDLER, handler);	
		  MainFrame mf = (MainFrame)fr;
		  ProfileCardPanel pp = mf.getProfilePanel();
		  CardLayout ppc = mf.getProfilePanelCard();
		  handler.setProfilePanel(pp);
		  handler.setProfilePanelCard(ppc);
		 }
	   }

  }
	
  public void actionPerformed(ActionEvent e) {
	  AbstractButton but = (AbstractButton)e.getSource();
	  ModeAction action = (ModeAction)but.getAction();
	  // LCWButton bPressed = (LCWButton)e.getSource();
	  MouseHandler h = (MouseHandler)action.getValue(LCW_MOUSEHANDLER);
	  Util.lookup.put(Util._CURR_MOUSE_HANDLER, h);
	  pbp.setMouseHandler(h);
  }
}
  
